clear all
close all
clc
s = serial('COM5');
%set(s,'BaudRate',921600);
set(s,'BaudRate',115200);  %1680 sps
%set(s,'BaudRate',230400); %1753 sps
set(s,'DataBits',8);
set(s,'StopBits',1);
fopen(s);


%dt = 56/1000/500; %56ms entre 2 mesures

Y = [0];
X = [0];
%tic;
for i = 1 : 2000
    out = fread(s, 1);
    if (out == 255)
        for j = 1 : 500
            temp = fread(s, 2);
            tt = temp(1)+temp(2)*256;
            if (tt <  1024)
               % X = [X (X(end)+dt)];
                Y = [Y tt];
            end
        end
    end   
    
   % if (mod(i,2000) == 0)
   %     plot(X,Y);
    %    drawnow;
   % end
end
%tfin = toc;
%sps = round(20000/tfin)

fclose(s);

% plot(X,Y);
 
%Y = csvread('adc moteur a fond.txt')
 figure;
 plot(Y);
 
 
%csvwrite('out.txt',Y);